﻿using Communergy.Repository.InMemory;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
namespace Communergy.Common.Tests
{
    
    
    /// <summary>
    ///This is a test class for InMemoryUnitOfWorkTest and is intended
    ///to contain all InMemoryUnitOfWorkTest Unit Tests
    ///</summary>
    [TestClass()]
    public class InMemoryUnitOfWorkTest
    {


        
        [TestMethod()]
        public void InMemoryUnitOfWork_AddASimpleMeterAndSave_ShouldBeAdded()
        {
            InMemoryUnitOfWork unitOfWork = new InMemoryUnitOfWork();
            Meter meter = new Meter { MeterName = "Meter" };
            unitOfWork.AddMeter(meter);
            unitOfWork.Save();
            List<Meter> meters = unitOfWork.Meters;
            Assert.AreEqual(1, meters.Count);
        }



        [TestMethod()]
        public void InMemoryUnitOfWork_AddASimpleMeterDoNotSave_ShouldNotBeAdded()
        {
            InMemoryUnitOfWork unitOfWork = new InMemoryUnitOfWork();
            Meter meter = new Meter { MeterName = "Meter" };
            unitOfWork.AddMeter(meter);
            List<Meter> meters = unitOfWork.Meters;
            Assert.AreEqual(0, meters.Count);
        }

        [TestMethod()]
        public void InMemoryUnitOfWork_AddASimpleMeterRollbackThenSave_ShouldNotBeAdded()
        {
            InMemoryUnitOfWork unitOfWork = new InMemoryUnitOfWork();
            Meter meter = new Meter { MeterName = "Meter" };
            unitOfWork.AddMeter(meter);
            unitOfWork.Rollback();
            unitOfWork.Save();
            List<Meter> meters = unitOfWork.Meters;
            Assert.AreEqual(0, meters.Count);
        }
    }
}
